package web.listener;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.apache.log4j.Logger;

import web.action.Action;

import agent.UserAgent;

import common.LogCategory;

/**
 * When session is about to be destroyed, the listener will write to the {@link LoginActivity the necessary information for the logout
 *
 */
public class BalkantonSessionListener implements HttpSessionListener {
	
	private static final Logger log = LogCategory.getCategory(BalkantonSessionListener.class);

	@Override
	public void sessionCreated(HttpSessionEvent arg0) {
		log.info("Session created");
		
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent event) {
		HttpSession session = event.getSession();
		String loggedUser = (String) session.getAttribute(Action.USERNAME);
		log.info("Session is destroyed");
		if (loggedUser != null) {
			UserAgent.getSole().userLogout(loggedUser);
			log.info("Deactivating expired normal log session " +loggedUser);
		}
		
		
	}

}
